#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
import shutil
sys.path.append("E:/SVN/SGSDK/SGTools/SGAutoPack/autopack_v4_ppl2")
import SwitchChannel
sys.path.append("E:/SVN/SGSDK/SGTools/SGAutoPack/SGPythonUtils")
import ConfigFileEdit

gamedir = "E:/gamecopy"
backupdir = "E:/SVN/SGSDK/SGTools/SGAutoPack/autopack_v4_ppl2/temp"
fourlib = "E:/SVN/SGSDK/SGSMS/FOUR"

#检查资源相关的目录是否存在
def checkDirExist():
	if(False == os.path.exists(gamedir)):
		print( gamedir + " is not exist")
		raise( gamedir + " is not exist")
	if(False == os.path.exists(backupdir)):
		print( backupdir + " is not exist")
		raise( backupdir + " is not exist")

#copy文件
def copyFileSafety(backupfile,desfile):
	if( True == os.path.exists(backupfile) ):
		if( True == os.path.exists(desfile) ):
			os.remove(desfile)
		shutil.copyfile(backupfile,desfile)

#创建目录
def createOneDirSafety(dirname):
	if(False == os.path.exists(dirname)):
		os.makedirs(dirname)

#删除目录
def deleteOneDirSafety(dirname):
	if(os.path.exists(dirname)):
		shutil.rmtree(dirname,True)

#调整资源
def channelCustomOperBegin():
#	#修改运营商
#	#其实如果是mm三网切jd，Manifest文件里的Main也要删掉(目前没做处理)
#	projectfile = fourlib + "/project.properties"
#	liblist = [
#		'..\\..\\SGUtil\\SGSDKUtils_Library',
#		'../SmsLib/sms_lib_ayx_4.2.0',
#		'../SmsLib/sms_lib_lt_4.0.2',
#		'../SmsLib/sms_lib_jd_26005_release'
#	]
#	ConfigFileEdit.setProjectRefLib(projectfile,liblist)
	
#	#payTypeConfig
#	xiaomiPayTypeConfig = backupdir + "/xiaomi/xiaomi_payTypeConfig.xml"
#	gamePayTypeConfig = gamedir + "/assets/soulgame/payTypeConfig.xml"
#	copyFileSafety(xiaomiPayTypeConfig,gamePayTypeConfig)

	#计费点文件
	backup_xiaomiparamsfile = backupdir + "/xiaomi/sg_sdk_params.info"
	game_xiaomiparamsfile = gamedir + "/assets/sg_sdk_params.info"
	copyFileSafety(backup_xiaomiparamsfile,game_xiaomiparamsfile)

#恢复资源
def channelCustomOperEnd():
	pass
#	#还原Four的配置(电信、联通、MM)
#	backupFourProjectFile = backupdir + "/four_project.properties"
#	fourProjectFile = fourlib + "/project.properties"
#	copyFileSafety(backupFourProjectFile,fourProjectFile)


if __name__=="__main__":
	if(sys.argv[1] == "begin"):
		channelCustomOperBegin()
	elif(sys.argv[1] == "end"):
		channelCustomOperEnd()
	else:
		raise("call channel custom operation must with param begin or end!")
#	channelCustomOperBegin()
#	channelCustomOperEnd()